<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>devcss_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_debug_devcss_devcss_test.js.html">devcss_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.debug.DevCssTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.debug.DevCssTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.debug.DevCss&#39;);
<a name="line19"></a>goog.require(&#39;goog.style&#39;);
<a name="line20"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line21"></a>
<a name="line22"></a>var el;
<a name="line23"></a>
<a name="line24"></a>function setUpPage() {
<a name="line25"></a>  el = document.getElementById(&#39;devcss-test-2&#39;);
<a name="line26"></a>}
<a name="line27"></a>
<a name="line28"></a>// Since background color sometimes comes back like rgb(xxx, xxx, xxx)
<a name="line29"></a>// or rgb(xxx,xxx,xxx) depending on browser.
<a name="line30"></a>function spaceless(foo) {
<a name="line31"></a>  return foo.replace(/\s/g, &#39;&#39;);
<a name="line32"></a>}
<a name="line33"></a>
<a name="line34"></a>function testGetIe6CombinedSelectorText() {
<a name="line35"></a>  var devcssInstance = new goog.debug.DevCss();
<a name="line36"></a>  devcssInstance.ie6CombinedMatches_ = [];
<a name="line37"></a>  var css = &#39;.class2 { -goog-ie6-selector:&quot;.class1_class2&quot;; prop: val; }&#39;;
<a name="line38"></a>  var newCss = devcssInstance.getIe6CombinedSelectorText_(css);
<a name="line39"></a>  assertEquals(&#39;.class1_class2&#39;, newCss);
<a name="line40"></a>  assertArrayEquals([&#39;class1&#39;, &#39;class2&#39;],
<a name="line41"></a>      devcssInstance.ie6CombinedMatches_[0].classNames);
<a name="line42"></a>  assertEquals(&#39;class1_class2&#39;,
<a name="line43"></a>      devcssInstance.ie6CombinedMatches_[0].combinedClassName);
<a name="line44"></a>
<a name="line45"></a>  devcssInstance = new goog.debug.DevCss();
<a name="line46"></a>  devcssInstance.ie6CombinedMatches_ = [];
<a name="line47"></a>  css = &#39;.class3 { prop: val; -goog-ie6-selector:&quot;.class1_class2_class3&quot;;&#39; +
<a name="line48"></a>      &#39;prop: val; }&#39;;
<a name="line49"></a>  newCss = devcssInstance.getIe6CombinedSelectorText_(css);
<a name="line50"></a>  assertEquals(&#39;.class1_class2_class3&#39;, newCss);
<a name="line51"></a>  assertArrayEquals([&#39;class1&#39;, &#39;class2&#39;, &#39;class3&#39;],
<a name="line52"></a>      devcssInstance.ie6CombinedMatches_[0].classNames);
<a name="line53"></a>  assertEquals(&#39;class1_class2_class3&#39;,
<a name="line54"></a>      devcssInstance.ie6CombinedMatches_[0].combinedClassName);
<a name="line55"></a>
<a name="line56"></a>  devcssInstance = new goog.debug.DevCss();
<a name="line57"></a>  devcssInstance.ie6CombinedMatches_ = [];
<a name="line58"></a>  css = &#39;.class3, .class5 {&#39; +
<a name="line59"></a>      &#39;-goog-ie6-selector:&quot;.class1_class2_class3, .class4_class5&quot;;&#39; +
<a name="line60"></a>      &#39;prop: val; }&#39;;
<a name="line61"></a>  newCss = devcssInstance.getIe6CombinedSelectorText_(css);
<a name="line62"></a>  assertEquals(&#39;.class1_class2_class3, .class4_class5&#39;, newCss);
<a name="line63"></a>  assertArrayEquals([&#39;class1&#39;, &#39;class2&#39;, &#39;class3&#39;],
<a name="line64"></a>      devcssInstance.ie6CombinedMatches_[0].classNames);
<a name="line65"></a>  assertEquals(&#39;class1_class2_class3&#39;,
<a name="line66"></a>      devcssInstance.ie6CombinedMatches_[0].combinedClassName);
<a name="line67"></a>  assertArrayEquals([&#39;class4&#39;, &#39;class5&#39;],
<a name="line68"></a>      devcssInstance.ie6CombinedMatches_[1].classNames);
<a name="line69"></a>  assertEquals(&#39;class4_class5&#39;,
<a name="line70"></a>      devcssInstance.ie6CombinedMatches_[1].combinedClassName);
<a name="line71"></a>}
<a name="line72"></a>
<a name="line73"></a>function testAddIe6CombinedClassNames() {
<a name="line74"></a>  var el_combined1 = document.getElementById(&#39;devcss-test-combined1&#39;);
<a name="line75"></a>  var el_combined2 = document.getElementById(&#39;devcss-test-combined2&#39;);
<a name="line76"></a>  var el_notcombined1 = document.getElementById(&#39;devcss-test-notcombined1&#39;);
<a name="line77"></a>  var el_notcombined2 = document.getElementById(&#39;devcss-test-notcombined2&#39;);
<a name="line78"></a>  var el_notcombined3 = document.getElementById(&#39;devcss-test-notcombined3&#39;);
<a name="line79"></a>
<a name="line80"></a>  var devcssInstance = new goog.debug.DevCss();
<a name="line81"></a>  devcssInstance.ie6CombinedMatches_ = [
<a name="line82"></a>    {
<a name="line83"></a>      classNames: [&#39;ie6-2&#39;, &#39;ie6-1&#39;],
<a name="line84"></a>      combinedClassName: &#39;ie6-1_ie6-2&#39;,
<a name="line85"></a>      els: []
<a name="line86"></a>    },
<a name="line87"></a>    {
<a name="line88"></a>      classNames: [&#39;ie6-2&#39;, &#39;ie6-3&#39;, &#39;ie6-1&#39;],
<a name="line89"></a>      combinedClassName: &#39;ie6-1_ie6-2_ie6-3&#39;,
<a name="line90"></a>      els: []
<a name="line91"></a>    }];
<a name="line92"></a>
<a name="line93"></a>  devcssInstance.addIe6CombinedClassNames_();
<a name="line94"></a>  assertEquals(-1, el_notcombined1.className.indexOf(&#39;ie6-1_ie6-2&#39;));
<a name="line95"></a>  assertEquals(-1, el_notcombined2.className.indexOf(&#39;ie6-1_ie6-2&#39;));
<a name="line96"></a>  assertEquals(-1, el_notcombined3.className.indexOf(&#39;ie6-1_ie6-2_ie6-3&#39;));
<a name="line97"></a>  assertTrue(el_combined1.className.indexOf(&#39;ie6-1_ie6-2&#39;) != -1);
<a name="line98"></a>  assertTrue(el_combined2.className.indexOf(&#39;ie6-1_ie6-2_ie6-3&#39;) != -1);
<a name="line99"></a>}
<a name="line100"></a>
<a name="line101"></a>function testActivateBrowserSpecificCssALL() {
<a name="line102"></a>  // equals GECKO
<a name="line103"></a>  var devcssInstance = new goog.debug.DevCss(&#39;GECKO&#39;);
<a name="line104"></a>  devcssInstance.activateBrowserSpecificCssRules(false);
<a name="line105"></a>  var backgroundColor = goog.style.getBackgroundColor(el);
<a name="line106"></a>  assertEquals(&#39;rgb(255,192,203)&#39;, spaceless(backgroundColor));
<a name="line107"></a>
<a name="line108"></a>  // GECKO test case w/ two selectors joined by a commma.
<a name="line109"></a>  var elGeckoOne = document.getElementById(&#39;devcss-gecko-1&#39;);
<a name="line110"></a>  backgroundColor = goog.style.getBackgroundColor(elGeckoOne);
<a name="line111"></a>  assertEquals(&#39;rgb(255,192,203)&#39;, spaceless(backgroundColor));
<a name="line112"></a>  var elGeckoTwo = document.getElementById(&#39;devcss-gecko-2&#39;);
<a name="line113"></a>  backgroundColor = goog.style.getBackgroundColor(elGeckoTwo);
<a name="line114"></a>  assertEquals(&#39;rgb(255,192,203)&#39;, spaceless(backgroundColor));
<a name="line115"></a>}
<a name="line116"></a>
<a name="line117"></a>
<a name="line118"></a>function testActivateBrowserSpecificCssWithVersion() {
<a name="line119"></a>  // equals IE 6
<a name="line120"></a>  var devcssInstance = new goog.debug.DevCss(&#39;IE&#39;, &#39;6&#39;);
<a name="line121"></a>  devcssInstance.activateBrowserSpecificCssRules(false);
<a name="line122"></a>  var elIe6 = document.getElementById(&#39;devcss-test-ie6&#39;);
<a name="line123"></a>  var backgroundColor = goog.style.getBackgroundColor(elIe6);
<a name="line124"></a>  assertEquals(&#39;rgb(255,192,203)&#39;, spaceless(backgroundColor));
<a name="line125"></a>
<a name="line126"></a>  // IE8 test case w/ two selectors joined by a commma.
<a name="line127"></a>  var devCssInstanceTwo = new goog.debug.DevCss(&#39;IE&#39;, &#39;8&#39;);
<a name="line128"></a>  devCssInstanceTwo.activateBrowserSpecificCssRules(false);
<a name="line129"></a>  var elIe8One = document.getElementById(&#39;devcss-ie8-1&#39;);
<a name="line130"></a>  backgroundColor = goog.style.getBackgroundColor(elIe8One);
<a name="line131"></a>  assertEquals(&#39;rgb(255,192,203)&#39;, spaceless(backgroundColor));
<a name="line132"></a>  var elIe8Two = document.getElementById(&#39;devcss-ie8-2&#39;);
<a name="line133"></a>  backgroundColor = goog.style.getBackgroundColor(elIe8Two);
<a name="line134"></a>  assertEquals(&#39;rgb(255,192,203)&#39;, spaceless(backgroundColor));
<a name="line135"></a>}
<a name="line136"></a>
<a name="line137"></a>function testActivateBrowserSpecificCssGteInvalid() {
<a name="line138"></a>  // WEBKIT_GTE255
<a name="line139"></a>  var marginBox = goog.style.getMarginBox(el);
<a name="line140"></a>  assertEquals(1, marginBox.top); // should still be 1
<a name="line141"></a>
<a name="line142"></a>  var devcssInstance = new goog.debug.DevCss(&#39;WEBKIT&#39;, 254);
<a name="line143"></a>  devcssInstance.activateBrowserSpecificCssRules(false);
<a name="line144"></a>  var marginBox = goog.style.getMarginBox(el);
<a name="line145"></a>  assertEquals(1, marginBox.top); // should still be 1
<a name="line146"></a>}
<a name="line147"></a>
<a name="line148"></a>function testActivateBrowserSpecificCssGteValid() {
<a name="line149"></a>  var devcssInstance = new goog.debug.DevCss(&#39;WEBKIT&#39;, 255);
<a name="line150"></a>  devcssInstance.activateBrowserSpecificCssRules(false);
<a name="line151"></a>  var marginBox = goog.style.getMarginBox(el);
<a name="line152"></a>  assertEquals(20, marginBox.top);
<a name="line153"></a>}
<a name="line154"></a>
<a name="line155"></a>function testActivateBrowserSpecificCssLteInvalid() {
<a name="line156"></a>  // IE_LTE6
<a name="line157"></a>  var marginBox = goog.style.getMarginBox(el);
<a name="line158"></a>  assertEquals(1, marginBox.left); // should still be 1
<a name="line159"></a>
<a name="line160"></a>  var devcssInstance = new goog.debug.DevCss(&#39;WEBKIT&#39;, 202);
<a name="line161"></a>  devcssInstance.activateBrowserSpecificCssRules(false);
<a name="line162"></a>  var marginBox = goog.style.getMarginBox(el);
<a name="line163"></a>  assertEquals(1, marginBox.left); // should still be 1
<a name="line164"></a>}
<a name="line165"></a>
<a name="line166"></a>function testActivateBrowserSpecificCssLteValid() {
<a name="line167"></a>  var devcssInstance = new goog.debug.DevCss(&#39;WEBKIT&#39;, 199);
<a name="line168"></a>  devcssInstance.activateBrowserSpecificCssRules(false);
<a name="line169"></a>  var marginBox = goog.style.getMarginBox(el);
<a name="line170"></a>  assertEquals(15, marginBox.left);
<a name="line171"></a>}
<a name="line172"></a>
<a name="line173"></a>function testReplaceIe6Selectors() {
<a name="line174"></a>  var devcssInstance = new goog.debug.DevCss(&#39;IE&#39;, 6);
<a name="line175"></a>  devcssInstance.activateBrowserSpecificCssRules(false);
<a name="line176"></a>
<a name="line177"></a>  // It should correctly be transparent, even in IE6.
<a name="line178"></a>  var compound2El = document.getElementById(&#39;devcss-test-compound2&#39;);
<a name="line179"></a>  var backgroundColor = spaceless(
<a name="line180"></a>      goog.style.getBackgroundColor(compound2El));
<a name="line181"></a>
<a name="line182"></a>  assertTrue(&#39;Unexpected background color: &#39; + backgroundColor,
<a name="line183"></a>      &#39;transparent&#39; == backgroundColor ||
<a name="line184"></a>      &#39;rgba(0,0,0,0)&#39; == backgroundColor);
<a name="line185"></a>
<a name="line186"></a>  // And this one should have the combined selector working, even in
<a name="line187"></a>  // IE6.
<a name="line188"></a>  backgroundColor = goog.style.getBackgroundColor(
<a name="line189"></a>      document.getElementById(&#39;devcss-test-compound1-2&#39;));
<a name="line190"></a>  assertEquals(&#39;rgb(255,192,203)&#39;, spaceless(backgroundColor));
<a name="line191"></a>}
<a name="line192"></a>
<a name="line193"></a>/*
<a name="line194"></a> * TODO(user): Re-enable if we ever come up with a way to make imports
<a name="line195"></a> * work.
<a name="line196"></a>function testDisableDuplicateStyleSheetImports() {
<a name="line197"></a>  var el1 = document.getElementById(&#39;devcss-test-importfixer-1&#39;);
<a name="line198"></a>  var el2 = document.getElementById(&#39;devcss-test-importfixer-2&#39;);
<a name="line199"></a>
<a name="line200"></a>  var backgroundColor = goog.style.getBackgroundColor(el1);
<a name="line201"></a>  assertEquals(&#39;rgb(255,255,0)&#39;, spaceless(backgroundColor));
<a name="line202"></a>
<a name="line203"></a>  var backgroundColor = goog.style.getBackgroundColor(el2);
<a name="line204"></a>  assertEquals(&#39;rgb(255,0,0)&#39;, spaceless(backgroundColor));
<a name="line205"></a>
<a name="line206"></a>  // This should disable the second coming of devcss_test_import_1.css.
<a name="line207"></a>  var devcssInstance = new goog.debug.DevCss();
<a name="line208"></a>  devcssInstance.disableDuplicateStyleSheetImports();
<a name="line209"></a>
<a name="line210"></a>  var backgroundColor = goog.style.getBackgroundColor(el1);
<a name="line211"></a>  assertEquals(&#39;rgb(255,255,0)&#39;, spaceless(backgroundColor));
<a name="line212"></a>
<a name="line213"></a>  var backgroundColor = goog.style.getBackgroundColor(el2);
<a name="line214"></a>  assertEquals(&#39;rgb(173,216,230)&#39;, spaceless(backgroundColor));
<a name="line215"></a>}
<a name="line216"></a>*/
</pre>


</body>
</html>
